import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'


const app = createApp(App)
const pinia = createPinia()

app.use(pinia)
app.use(router)
app.use(ElementPlus)

// 确保在挂载前初始化认证状态
const initializeApp = async () => {
  try {
    // 必须在app.use(pinia)之后才能使用store
    const authStore = (await import('@/stores/auth')).useAuthStore()
    authStore.initializeAuth()
    
    // 确保路由已准备好
    await router.isReady()
    
    app.mount('#app')
  } catch (error) {
    console.error('应用初始化失败:', error)
    // 即使初始化失败也挂载应用，让应用可以显示错误页面
    app.mount('#app')
  }
}

initializeApp()